package com.cspg.ssss.job;

import com.cspg.ssss.service.DailyMessageService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Calendar;

/**
 * 每日消息通知Job
 */
public class SendMsgJob extends QuartzJobBean {
    private static final Logger log = LoggerFactory.getLogger(SendMsgJob.class);

    @Autowired
    DailyMessageService dailyMessageService;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("start DailyMessagejob ......++ ");
        //判断是否工作日，否则不发送
        Calendar today = Calendar.getInstance();
        int dayOfWeek = today.get(Calendar.DAY_OF_WEEK);
        if(dayOfWeek == 1 || dayOfWeek == 7){
            log.info("周末不发消息---------");
            return;
        }
        boolean iscloseMsg = true;
        if(iscloseMsg){
            log.info("暂时关闭每日群发发消息---------");
            return;
        }
        dailyMessageService.sendDailyMessage(0);
        dailyMessageService.sendDailyMessage(1);
        dailyMessageService.sendRectifyMessage();
        log.info("end DailyMessagejob ......++ ");
    }
}
